package com.kh.tool.exceldatachecker;

public interface ExcelCheckerGenerator {
    /***
     * 获取身份证校验器
     * @return
     */
    default ExcelDataParser.BusinessChecker getCardIdChecker() {
        return (toBeVerified) -> {
            final boolean matches = toBeVerified.getValue().matches("\\d{17}[X|\\d]");
            if (!matches) {
                toBeVerified.setErrorMsg("请输入18位有效身份证号码");
            }
            return matches;
        };
    }

    /**
     * 获取企业名称校验器
     * @return
     */
    default ExcelDataParser.BusinessChecker getEnterpriseNameChecker() {
        return toBeVerified -> {
            boolean matches = toBeVerified.getValue().matches("[\\u4e00-\\u9fa5a-zA-Z0-9]{1,50}");
            if (!matches) {
                toBeVerified.setErrorMsg("请输入长度50以内的汉字、字母或数字");
            }
            return matches;
        };
    }

    /***
     * 获取个体名称校验器
     * @return
     */
    default ExcelDataParser.BusinessChecker getFullNameChecker() {
        return toBeVerified -> {
            boolean matches = toBeVerified.getValue().matches("^[\\u4E00-\\u9FA5a-zA-Z·0-9]{1,50}$");
            if (!matches) {
                toBeVerified.setErrorMsg("请输入长度50以内的汉字");
            }
            return matches;
        };
    }

    /***
     * 获取手机号校验器
     * @return
     */
    default ExcelDataParser.BusinessChecker getPhoneChecker() {
        return toBeVerified -> {
            boolean matches = toBeVerified.getValue().matches("^((1[3-9]))\\d{9}$");
            if (!matches) {
                toBeVerified.setErrorMsg("请输入11位手机号");
            }
            return matches;
        };
    }

    /***
     * 获取统一社会信用代码校验器
     * @return
     */
    default ExcelDataParser.BusinessChecker getUnifiedSocialCreditCodeChecker() {
        return toBeVerified -> {
            final boolean matches = toBeVerified.getValue().matches("[a-zA-Z0-9]{18}");
            if (!matches) {
                toBeVerified.setErrorMsg("请输入18位有效统一社会信用代码");
            }
            return matches;
        };
    }



    /***
     * 获取数据库校验器
     * @return
     */
    ExcelDataParser.BusinessChecker getDbChecker();
}
